package com.ruoyi.erecord.vehicles.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.erecord.employee.domain.bo.EmployeeImportBo;
import com.ruoyi.erecord.vehicles.domain.bo.VehiclesImportAttachBo;
import com.ruoyi.erecord.vehicles.domain.bo.VehiclesImportBo;
import com.ruoyi.erecord.vehicles.domain.vo.VehiclesImportAttachVo;
import com.ruoyi.erecord.vehicles.service.IVehiclesImportAttachService;
import com.ruoyi.erecord.vehicles.service.impl.VehiclesImportExcelService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 车辆导入附件
 *
 * @author cc
 * @date 2023-04-18
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/erecord/vehiclesImportAttach")
public class VehiclesImportAttachController extends BaseController {

    private final IVehiclesImportAttachService iVehiclesImportAttachService;
    private final VehiclesImportExcelService vehiclesImportExcelService;
    
    /**
     * 查询车辆导入附件列表
     */
    @SaCheckPermission("erecord:vehiclesImportAttach:list")
    @GetMapping("/list")
    public TableDataInfo<VehiclesImportAttachVo> list(VehiclesImportAttachBo bo, PageQuery pageQuery) {
        return iVehiclesImportAttachService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出车辆导入附件列表
     */
    @SaCheckPermission("erecord:vehiclesImportAttach:export")
    @Log(title = "车辆导入附件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(VehiclesImportAttachBo bo, HttpServletResponse response) {
        List<VehiclesImportAttachVo> list = iVehiclesImportAttachService.queryList(bo);
        ExcelUtil.exportExcel(list, "车辆导入附件", VehiclesImportAttachVo.class, response);
    }

    /**
     * 获取车辆导入附件详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("erecord:vehiclesImportAttach:query")
    @GetMapping("/{id}")
    public R<VehiclesImportAttachVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iVehiclesImportAttachService.queryById(id));
    }

    /**
     * 新增车辆导入附件
     */
    @SaCheckPermission("erecord:vehiclesImportAttach:add")
    @Log(title = "车辆导入附件", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody VehiclesImportAttachBo bo) {
        return toAjax(iVehiclesImportAttachService.insertByBo(bo));
    }

    /**
     * 修改车辆导入附件
     */
    @SaCheckPermission("erecord:vehiclesImportAttach:edit")
    @Log(title = "车辆导入附件", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody VehiclesImportAttachBo bo) {
        return toAjax(iVehiclesImportAttachService.updateByBo(bo));
    }

    /**
     * 删除车辆导入附件
     *
     * @param ids 主键串
     */
    @SaCheckPermission("erecord:vehiclesImportAttach:remove")
    @Log(title = "车辆导入附件", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iVehiclesImportAttachService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
    
    @SaCheckPermission("erecord:vehiclesImportAttach:import")
    @Log(title = "车辆导入附件", businessType = BusinessType.IMPORT)
    @RepeatSubmit()
    @PostMapping("/importAttach")
    public R<Void> importAttach(@Validated(AddGroup.class) @RequestBody VehiclesImportBo bo) {
        return toAjax(this.vehiclesImportExcelService.importZip(bo));
    }
}
